<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="/views/common/header.jsp" %>

<div class="box">
  <div class="box-header">
    <c:if test="${parent == 0 }">
    <h3 class="box-title">一级分类</h3>
    </c:if>
    <c:if test="${parent != 0 }">
    <h3 class="box-title">${parent_name }的二级分类</h3>
    </c:if>
    <div class="box-tools">
      <ul class="pagination pagination-sm no-margin pull-right">
        <c:set var="currentPage" value="${type_list.pageNumber}" />
        <c:set var="totalPage" value="${type_list.totalPage}" />
        <c:set var="actionUrl" value="/restype/list" />
        <c:set var="urlParas" value="&parent=${parent }" />
        <c:set var="in_table" value="1" />
        <%@ include file="/views/common/_paginate.jsp" %>
      </ul>
    </div>
  </div><!-- /.box-header -->
  <div class="box-body no-padding">
    <table class="table">
      <tbody><tr>
        <th>ID</th>
        <th>分类名称</th>
        <c:if test="${parent == 0 }">
        <th>子分类数</th>
        </c:if>
        <th>资源数</th>
        <th>操作</th>
      </tr>
      <c:forEach var="type" items="${type_list.list }">
      <tr>
        <td>${type.id }.</td>
        <td>${type.name }</td>
        <c:if test="${parent == 0 }">
        <td>${type.subcount }</td>
        </c:if>
        <td>${type.rescount }</td>
        <td>
            <c:if test="${parent == 0 }">
            <a class="text-green" href="/restype/list/?parent=${type.id }">查看子分类</a> | 
            </c:if>
            <a href="/restype/edit/?cate-id=${type.id }">修改</a> | 
            <a class="text-red" href="javascript:doDelete(${type.id })">删除</a>
        </td>
      </tr>
      </c:forEach>
    </tbody></table>
  </div><!-- /.box-body -->
</div>
<c:set var="in_table" value="0" />
<%@ include file="/views/common/_paginate.jsp" %>
<script>
function doDelete(id)
{
	swal({
		title: "Are you sure?",
		text: "Your will not be able to recover this imaginary file!",
		type: "warning",
		showCancelButton: true,
		confirmButtonColor: "#DD6B55",
		confirmButtonText: "Yes, delete it!",
		cancelButtonText: "No, cancel plx!",
		closeOnConfirm: false,
		closeOnCancel: false 
	}, function (isConfirm){
		if (isConfirm) {
			$.ajax({
		        'data': {'id':id},
		        'dataType': 'JSON',
		        'url': '/restype/delete',
		        'type': 'post',
		        'success': function (ret){
		            if (parseInt(ret.code) != 200)
		            {
		                swal('删除失败', ret.msg, 'error');
		                return false;
		            }
		            window.location.reload()
		        }
		    })
		} else {
		    swal("Cancelled", "Your imaginary file is safe :)", "error");
		} 
	})
	
}
</script>

<%@ include file="/views/common/footer.jsp" %>